package com.xwltz.controller;

import com.xwltz.model.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
@RequestMapping("/index")
public class IndexController {

    @RequestMapping("/map")
    public String map(Map<String, UserInfo> userInfoMap) {
        UserInfo user = new UserInfo();
        user.setId(1);
        user.setName("com.xwltz");
        userInfoMap.put("user", user);
        return "index";
    }

    @RequestMapping("/model")
    public String model(Model model) {
        UserInfo user = new UserInfo();
        user.setId(1);
        user.setName("com.xwltz");
        model.addAttribute("user", user);
        return "index";
    }

    @RequestMapping("/modelAndView")
    public ModelAndView modelAndView() {
        UserInfo user = new UserInfo();
        user.setId(1);
        user.setName("com.xwltz");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", user);
        modelAndView.setViewName("index");
        return modelAndView;
    }
}
